package com.wxy.common.utils;

import com.github.dozermapper.core.Mapper;
import com.github.dozermapper.core.MappingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class DozerUtil {
    @Autowired
    private Mapper dozerMapper;

    public <T> T map(Object object, Class<T> clz) throws MappingException {
        return dozerMapper.map(object, clz);
    }

    public <T1, T2> List<T2> maps(List<T1> objects, Class<T2> clz) throws MappingException {
        List<T2> list = new ArrayList<>();
        for (T1 object : objects){
            list.add(map(object, clz));
        }
        return list;
    }

}
